// pages/print/shopDetail/shopDetail.js
const utils = require("../../../utils/utils");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        from: '1',
        firstOpen: 0
    },
    goPrice(e) {
        var id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/print/priceList/priceList?sn=' + id,
        })
    },
    goLocationPrint(e) {
        var lat = e.currentTarget.dataset.lat;
        var name = e.currentTarget.dataset.name;
        var address = e.currentTarget.dataset.address;
        var lon = e.currentTarget.dataset.lon;
        wx.openLocation({
            name: name,
            address: address,
            latitude: parseFloat(lat),
            longitude: parseFloat(lon),
            scale: 18
        })
    },
    goPrint(e) {
        var printId = e.currentTarget.dataset.id;
        wx.setStorageSync('machineQrCode', printId)
        if (utils.is_define(this.data.from)) {
            wx.navigateBack({
                delta: 2
            })
        } else {
            wx.switchTab({
                url: '/pages/index/index',
            })
        }
        // if (this.data.from != '1') {
        //     console.log(this.data.from)
        //     console.log('1')

        // } else {
        //     console.log('2')

        //     qq.switchTab({
        //         url: '/pages/index/index'
        //     })
        // }

    },
    getIndex() {
        var that = this;
        utils.request('home/nearbyListDetail/' + that.data.id, {}, function (res) {
            wx.hideLoading()
            if (res.data.code == 200) {
                that.setData({
                    info: res.data.data,
                })
            } else {
                utils.toast(res.data.msg)
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this;
        wx.setNavigationBarTitle({
            title: options.shopName,
        })
        that.setData({
            title: options.shopName,
            id: options.id,
            from: options.from || ''
        })
        that.getIndex();
        wx.getSystemInfo({
            success: (result) => {
                var model = result.model;
                if (model == 'iPhone X') {
                    that.setData({
                        pdbottom: '68',
                    })
                } else {
                    that.setData({
                        pdbottom: '40'
                    })
                }
            },
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        var that = this;
        if (that.data.firstOpen == 1) {
            that.getIndex()
        } else {
            that.setData({
                firstOpen: 1
            })
        }

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        var that = this;
        return {
            title: that.data.info.shopName,
            imageUrl: that.data.info.shopPhoto + '?x-oss-process=image/resize,m_fill,w_1000,h_800,limit_0/quality,Q_100/auto-orient,0',
            path: "/pages/print/shopDetail/shopDetail?id=" + that.data.id + '&shopName=' + that.data.title
        }
    }
})